package com.syg.logback.core;

import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;

/**
 * @author syg
 * @version 1.0
 * @date 2021年11月24日19:14:46
 */
public class SqlLogInfBuilder implements Serializable {

    private static final long serialVersionUID = 8593738545459226676L;

    private String sqlId;
    private String sqlName;
    private String sqlClassPath;
    private String sqlMethod;
    private String sqlCommandType;
    private String datasourceType;
    private String sql;
    private long exeTm;
    private String exeSts;
    private String sqlParamJson;
    private String respCode;
    private String respMsg;

    public SqlLogInfBuilder() {
    }

    public String getSqlId() {
        return this.sqlId;
    }

    public SqlLogInfBuilder setSqlId(String sqlId) {
        this.sqlId = sqlId;
        if (StringUtils.isEmpty(sqlId)) {
            return this;
        } else {
            String[] array = sqlId.split("\\.");
            if (array.length > 2) {
                this.sqlName = array[array.length - 2] + "." + array[array.length - 1];
                this.sqlMethod = array[array.length - 1];
                this.sqlClassPath = sqlId.substring(0, sqlId.lastIndexOf("."));
            }

            return this;
        }
    }

    public String getSqlCommandType() {
        return this.sqlCommandType;
    }

    public SqlLogInfBuilder setSqlCommandType(String sqlCommandType) {
        this.sqlCommandType = sqlCommandType;
        return this;
    }

    public String getDatasourceType() {
        return this.datasourceType;
    }

    public SqlLogInfBuilder setDatasourceType(String datasourceType) {
        this.datasourceType = datasourceType;
        return this;
    }

    public String getSql() {
        return this.sql;
    }

    public SqlLogInfBuilder setSql(String sql) {
        this.sql = sql;
        return this;
    }

    public long getExeTm() {
        return this.exeTm;
    }

    public SqlLogInfBuilder setExeTm(long exeTm) {
        this.exeTm = exeTm;
        return this;
    }

    public String getSqlParamJson() {
        return this.sqlParamJson;
    }

    public SqlLogInfBuilder setSqlParam(Object sqlParamObject) {
        if (sqlParamObject == null) {
            return this;
        } else {
            this.sqlParamJson = "";
            return this;
        }
    }

    public String getRespCode() {
        return this.respCode;
    }

    public SqlLogInfBuilder setRespCode(String respCode) {
        if (StringUtils.isEmpty(respCode)) {
            return this;
        } else {
            if (respCode.length() > 10) {
                respCode = respCode.substring(0, 10);
            }

            this.respCode = respCode;
            return this;
        }
    }

    public String getRespMsg() {
        return this.respMsg;
    }

    public SqlLogInfBuilder setRespMsg(String respMsg) {
        if (StringUtils.isEmpty(respMsg)) {
            return this;
        } else {
            if (respMsg.length() > 200) {
                respMsg = respMsg.substring(0, 200);
            }

            this.respMsg = respMsg;
            return this;
        }
    }

    public String getExeSts() {
        return this.exeSts;
    }

    public SqlLogInfBuilder setExeSts(String exeSts) {
        this.exeSts = exeSts;
        return this;
    }

    public String getSqlName() {
        return this.sqlName;
    }

    public String getSqlClassPath() {
        return this.sqlClassPath;
    }

    public String getSqlMethod() {
        return this.sqlMethod;
    }

    public SqlLogInf build() {
        return new SqlLogInf(this);
    }
}
